package com.hht.toolanduilibs.widget

import android.annotation.SuppressLint
import android.content.Context
import android.text.TextUtils
import android.util.AttributeSet
import android.view.View
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.appcompat.widget.AppCompatTextView


/**
 * Author:chen'hu
 * Time:2023/8/7 10:20
 * Description:This is MarqueeTextView
 */
@SuppressLint("NewApi")
class MarqueeTextView : AppCompatTextView {
    constructor(context: Context) : this(context, null)
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context, attrs, defStyleAttr
    )


    init {
        this.isSingleLine = true
        this.ellipsize = TextUtils.TruncateAt.MARQUEE
        this.marqueeRepeatLimit = -1;//死循环
    }

    override fun isFocused(): Boolean {
        return true
    }

    /**
     * set view drawable
     * @param child
     * @param left
     * @param top
     * @param right
     * @param bottom
     */
    fun setDrawables(
        child: View?,
        @DrawableRes left: Int,
        @DrawableRes top: Int,
        @DrawableRes right: Int,
        @DrawableRes bottom: Int
    ) {
        if (child != null && child is TextView) {
            (child as TextView).setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
        }
    }
}